<?php
/**
 * Zead
 *
 * LICENSE	
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to eu@marcelomx.com so we can send you a copy immediately.
 *
 * @category   Zead
 * @author     Marcelo Rodrigues Gonzaga <eu@marcelomx.com>
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga
 * @link       http://code.google.com/p/zead 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License
 *
 **/


/** @see Zead_Html_Filter_Abstract **/
require_once 'Zead/Html/Filter/Abstract.php';

/**
 * @category   Zead
 * @package    Zead_Html
 * @subpackage Zead_Html_Filter
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License  
 */
class Zead_Html_Filter_BreadCrumb extends Zead_Html_Filter_Abstract
{
	/**
	 * Aplica o filtro que tem a função de procurar elementos com o id siteName ou outro
	 * passado como argumento que será o título do site.
	 *
	 * @param array  $contentsList
	 * @param string $baseUri
	 * @param string $separator
	 * @param string $selector
	 * <code>
	 *  $contentsList = array(
	 	0 => array(
			'text'  => 'Item label',
			'href'  => 'content/href.html',
			'title' => 'Item title'
		);
	    );
	 * </code>
	 */
	public function filter($pagesRange, $separator = '»', $selector = 'div.breadCrumb') 
	{
		// Retrieve elements
		$elements = $this->html->documentElement->select($selector);
		
		// If no has elements width css selector
		if (!$elements->count()) return;
				
		// Build the html
		$html = array();		
		foreach ($pagesRange as $key => $page) {
			if (($key + 1) < $pagesRange->count()) {
				$html[] = '<a href="'. $page->url . '">'. $page->label . '</a>';
			} else {
				$html[] = '<span class="current"> ' . $page->label . '</span>';
			}
		}
		$html = implode(' <span class="separator">' . $separator . '</span> ', $html);
		
		// Update elements with breadCrumb		
		foreach ($elements as $element) $element->update($html);
	}
}

